import { getStream } from '../Core/connect'
import { Vector2 } from '../Math/Vector2'
import * as MathUtils from '../Math/MathUtils'



export class MiniMap {
    actorUuid:String
    name: string
    uuid: string
    MapPosition: Vector2
    OriginPosition: Vector2
    AreaSize: Vector2
    ImgSize: Vector2
    PlayAngle:string
    url:String
    // listenmessagefun:Function
    constructor(option: MiniMapOption) {
        this.actorUuid = option.actorUuid
        this.uuid = MathUtils.generateUUID()
        this.name = option.name
        this.MapPosition = option.MapPosition ? option.MapPosition : new Vector2(0, 0)
        this.OriginPosition = option.OriginPosition ? option.OriginPosition : new Vector2(0, 0)
        this.AreaSize = option.AreaSize ? option.AreaSize : new Vector2(0, 0)
        this.ImgSize = option.ImgSize ? option.ImgSize : new Vector2(0, 0)
        this.PlayAngle = option.PlayAngle ? option.PlayAngle : '0'
        this.url = option.url
        this.init()
    }
    init() {
        const stream = getStream()
        const str = { 
            MiniMapfunction: 'creatMinimap',
            actorUuid:this.actorUuid,
            ids: `${this.name},${this.uuid}`, 
            MapPosition: `${this.MapPosition.x},${this.MapPosition.y},${0}`,
            OriginPosition: `${this.OriginPosition.x},${this.OriginPosition.y},${0}`,
            AreaSize: `${this.AreaSize.x},${this.AreaSize.y},${0}`,
            ImgSize: `${this.ImgSize.x},${this.ImgSize.y},${0}`,
            url:`${this.url}`,
            PlayAngle:`${this.PlayAngle}`
        }
        console.log(str)
        stream.emitUIInteraction(str)
    }

    //设置小地图位置
     setPosition(MapPosition: Vector2) {
         this.MapPosition = MapPosition
         const stream = getStream()
         const str = {MiniMapfunction: 'setMapPosition', ids: `${this.uuid}`, MapPosition: `${this.MapPosition.x},${this.MapPosition.y},${0}`}
         stream.emitUIInteraction(str)
     }
     //设置小地图大小
     setImgSize(ImgSize: Vector2) {
         this.ImgSize = ImgSize
         const stream = getStream()
         const str = {MiniMapfunction: 'setImgSize', ids: `${this.uuid}`, ImgSize: `${this.ImgSize.x},${this.ImgSize.y},${0}`}
         stream.emitUIInteraction(str)
     }
     //设置地图底图
     seturl(url: string) {
         this.url = url
         const stream = getStream()
         const str = {MiniMapfunction: 'seturl', ids: `${this.uuid}`, url: `${url}`}
         stream.emitUIInteraction(str)
     }
     //设置地图覆盖场景长宽
     setAreaSize(AreaSize: Vector2) {
         this.AreaSize = AreaSize
         const stream = getStream()
         const str = {MiniMapfunction: 'setAreaSize', ids: `${this.uuid}`, AreaSize: `${this.AreaSize.x},${this.AreaSize.y},${0}`}
         stream.emitUIInteraction(str)
     }
     //设置地图左上角点位坐标
     setOriginPosition(OriginPosition: Vector2) {
         this.OriginPosition = OriginPosition
         const stream = getStream()
         const str = {MiniMapfunction: 'setOriginPosition', ids: `${this.uuid}`, OriginPosition: `${this.OriginPosition.x},${this.OriginPosition.y},${0}`}
         stream.emitUIInteraction(str)
     }
}
